<?php  namespace Home\Controller;
class CartController extends CommonController
{
	public function index()
	{
		$GoodsData = Db::table('goods')->limit(5)->get();
		View::with('GoodsData',$GoodsData);
		if(!isset($_SESSION['cart'])){
			$_SESSION['cart']['goods'] = array();
		}else{
			$shuju = $_SESSION['cart']['goods'];
//			p($shuju);
			View::with('shuju',$shuju);
		}
		$zongjia = Cart::getTotalPrice();
		View::with('zongjia',$zongjia);
//		p($_SESSION);
		View::make();
	}
	public function del()
	{
//		p($_SESSION);
		$sid = $_POST['sjsid'];
//		p($sid);
		$data=array( 
    	'sid'=>$sid,// 唯一 sid，添加购物车时自动生成 
  	  	'num'=>0
		); 
		Cart::update($data); 
	}
	public function maxdel()
	{
		unset($_SESSION['cart']);
		View::success('清空成功',U('index'));
	}
	public function jiafa()
	{
		$jiafa = explode(',', $_POST['jf']);
		$data=array( 
    	'sid'=>$jiafa[0],// 唯一 sid，添加购物车时自动生成 
  	  	'num'=>$jiafa[1]
		); 
		Cart::update($data); 
		if($data){
			echo $jiafa[1];
		}
	}
	public function jianfa()
	{
		$jiafa = explode(',', $_POST['jian']);
		$data=array( 
    	'sid'=>$jiafa[0],// 唯一 sid，添加购物车时自动生成 
  	  	'num'=>$jiafa[1]
		); 
		Cart::update($data); 
		if($data){
			echo $jiafa[1];
		}
	}
}
